#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>

//int fun(unsigned int x)
//{
//	int n = 0;
//	while (x + 1)
//	{
//		n++;
//		x = x | (x + 1);
//	} 
//	return n;
//}

//00000000 00000000 00000111 11011110
//0111 1101 1110 +1
//0111 1101 1111
//0111 1101 1111 +1
//0111 1110 0000
//0111 111111111 +1

int fun(char* s)
{
	char* t = s;
	while (*t++);
	return(t - s);
}
//int main()
//{
//	//int x = fun(2014);
//	//int a[8] = { 0 };
//	//printf("%p\n", &a[0] + 1);
//	//printf("%p\n", &a[1]);
//	//printf("%p\n", a + 1);
//	////printf("%p\n", &a[0]++);
//	//int* p = &a[0];
//	//printf("%p\n", ++p);
//
//	////int a = 0;
//
//	//double x = 0.0;
//	//scanf("%lf", &x);
//	//printf("%lf", x);
//
//	//char ch[] = "abc";
//	//int x = fun(ch);
//
//	//float a[3] = { 1.5,2.5,3.5 }, *pa = a;
//	//*(pa++) *= 3;
//	//printf("%f", *pa);
//
//	//int a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, * p = a + 5, * q = NULL;
//	//*q = *(p + 5);
//	//printf("%d %d\n", *p, *q);
//
//	int a = 99999;
//	double* p = &a;
//	printf("%d\n", *p);
//	printf("%d", a);
//	return 0;
//}
typedef struct S
{
    int val;
    int i;
}S;
int cmp(const void* s1, const void* s2)
{
    return (((S*)s1)->val) - (((S*)s2)->val);
}


int* twoSum(int* numbers, int numbersLen, int target)
{
    S* tmp = (S*)malloc(numbersLen * sizeof(S));
    if (tmp == NULL)
        return NULL;

    int i = 0;
    for (i = 0; i < numbersLen; i++)
    {
        tmp[i].val = numbers[i];
        tmp[i].i = i + 1;
    }
    qsort(tmp, numbersLen, sizeof(S), cmp);

    int left = 0;
    int right = numbersLen - 1;
    while (left < right)
    {
        if (tmp[left].val + tmp[right].val < target)
            left++;
        else if (tmp[left].val + tmp[right].val > target)
            right--;
        else
            break;
    }

    int* arr = (int*)malloc(8);
    arr[0] = tmp[left].i;
    arr[1] = tmp[right].i;
    //*returnSize = 2;

    return arr;
}
int* masterMind(char* solution, char* guess, int* returnSize)
{
    int* answer = (int*)calloc(2, sizeof(int));
    int i = 0;
    for (i = 0; i < 4; i++)
    {
        if (solution[i] == guess[i])
        {
            answer[0]++;
            guess[i] = ' ';
            solution[i] = ' ';
        }
    }

    for (i = 0; i < 4; i++)
    {
        int j = 0;
        for (j = 0; j < 4; j++)
        {
            if (solution[i] == guess[j] && solution[i] != ' ')
            {
                answer[1]++;
                guess[j] = ' ';
                break;
            }
        }
    }
    *returnSize = 2;
    return answer;
}
int main()
{
    int arr[] = { 3,2,4 };
    int target = 6;
    int* x = twoSum(arr, 3, target);
    return 0;
}